<?php
if (isset($_POST['btnEliminar'])) {
    $link = mysql_connect("localhost", "root", "");
    mysql_select_db("sirpof_db1", $link);
    mysql_set_charset('utf8', $link);
    $id = $_POST["idpaciente"];
    //echo $id;
    $sqlproducto = "SELECT * FROM paciente_odontograma_post WHERE id_paciente = $id";
    $sqlproducto1 = mysql_query($sqlproducto, $link);
    //echo $sqlproducto."<br />";
    $i = 0;
    while ($sqlRow = mysql_fetch_row($sqlproducto1)) {
        $id_registro = $sqlRow[0];
        //echo $id_registro;
        $sqlEliminar = "delete from odontogramapost where id_registro = $id_registro";
        $sqlEliminar2 = "delete from paciente_odontograma_post where id_registro = $id_registro";
        $sqlEliminar3 = "delete from paciente_postmorten where id_pacientepost = $id";
        
        mysql_query($sqlEliminar, $link);
        mysql_query($sqlEliminar2, $link);
        mysql_query($sqlEliminar3, $link);

    }
    //var_dump($sqlproducto);
    header("Location: listpostmorten.php");
    exit();
}
?>

<?php
$id = $_GET["eliminar"];
//echo $id;
?>

<div>
    <center>
        <p>Esta seguro que desea 
            eliminar este registro.</p>
        <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
            <input type="hidden" value="<?php echo $id; ?>" name="idpaciente"/>
            <input type="submit" class="button" value="Aceptar" name="btnEliminar"/>
        </form>
    </center>
</div>

